using module mode; GOMOD=/home/client/go/src/github.com/linchao/zkp-authentication/go.mod
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#375EAB">

  <title>cp_zkp - Go Documentation Server</title>

<link type="text/css" rel="stylesheet" href="/lib/godoc/style.css">

<script>window.initFuncs = [];</script>
<script src="/lib/godoc/jquery.js" defer></script>



<script>var goVersion = "go1.20.4";</script>
<script src="/lib/godoc/godocs.js" defer></script>
</head>
<body>

<div id='lowframe' style="position: fixed; bottom: 0; left: 0; height: 0; width: 100%; border-top: thin solid grey; background-color: white; overflow: auto;">
...
</div><!-- #lowframe -->

<div id="topbar" class="wide"><div class="container">
<div class="top-heading" id="heading-wide"><a href="/pkg/">Go Documentation Server</a></div>
<div class="top-heading" id="heading-narrow"><a href="/pkg/">GoDoc</a></div>
<a href="#" id="menu-button"><span id="menu-button-arrow">&#9661;</span></a>
<form method="GET" action="/search">
<div id="menu">

<span class="search-box"><input type="search" id="search" name="q" placeholder="Search" aria-label="Search" required><button type="submit"><span><!-- magnifying glass: --><svg width="24" height="24" viewBox="0 0 24 24"><title>submit search</title><path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"/><path d="M0 0h24v24H0z" fill="none"/></svg></span></button></span>
</div>
</form>

</div></div>



<div id="page" class="wide">
<div class="container">


  <h1>
    Package cp_zkp
    <span class="text-muted"></span>
  </h1>







<div id="nav"></div>


<!--
	Copyright 2009 The Go Authors. All rights reserved.
	Use of this source code is governed by a BSD-style
	license that can be found in the LICENSE file.
-->
<!--
	Note: Static (i.e., not template-generated) href and id
	attributes start with "pkg-" to make it impossible for
	them to conflict with generated attributes (some of which
	correspond to Go identifiers).
-->

	<script>
	document.ANALYSIS_DATA = null;
	document.CALLGRAPH = null;
	</script>

	
		
		<div id="short-nav">
			<dl>
			<dd><code>import "github.com/linchao/zkp_auth/internal/cpzkp"</code></dd>
			</dl>
			<dl>
			<dd><a href="#pkg-overview" class="overviewLink">Overview</a></dd>
			<dd><a href="#pkg-index" class="indexLink">Index</a></dd>
			
			
			</dl>
		</div>
		<!-- The package's Name is printed as title by the top-level template -->
		<div id="pkg-overview" class="toggleVisible">
			<div class="collapsed">
				<h2 class="toggleButton" title="Click to show Overview section">Overview ▹</h2>
			</div>
			<div class="expanded">
				<h2 class="toggleButton" title="Click to hide Overview section">Overview ▾</h2>
				
				
			</div>
		</div>

		<div id="pkg-index" class="toggleVisible">
		<div class="collapsed">
			<h2 class="toggleButton" title="Click to show Index section">Index ▹</h2>
		</div>
		<div class="expanded">
			<h2 class="toggleButton" title="Click to hide Index section">Index ▾</h2>

		<!-- Table of contents for API; must be named manual-nav to turn off auto nav. -->
			<div id="manual-nav">
			<dl>
			
			
			
			
				
				<dd><a href="#CPZKP">type CPZKP</a></dd>
				
					
					<dd>&nbsp; &nbsp; <a href="#NewCPZKP">func NewCPZKP() (*CPZKP, error)</a></dd>
				
				
					
					<dd>&nbsp; &nbsp; <a href="#CPZKP.InitCPZKPParams">func (zkp *CPZKP) InitCPZKPParams() (*CPZKPParams, error)</a></dd>
				
			
				
				<dd><a href="#CPZKPParams">type CPZKPParams</a></dd>
				
				
			
				
				<dd><a href="#Prover">type Prover</a></dd>
				
					
					<dd>&nbsp; &nbsp; <a href="#NewProver">func NewProver(x *big.Int) *Prover</a></dd>
				
				
					
					<dd>&nbsp; &nbsp; <a href="#Prover.CreateProofChallengeResponse">func (p *Prover) CreateProofChallengeResponse(k, c *big.Int, params *CPZKPParams) (s *big.Int)</a></dd>
				
					
					<dd>&nbsp; &nbsp; <a href="#Prover.CreateProofCommitment">func (p *Prover) CreateProofCommitment(params *CPZKPParams) (k, r1, r2 *big.Int, err error)</a></dd>
				
					
					<dd>&nbsp; &nbsp; <a href="#Prover.GenerateYValues">func (p *Prover) GenerateYValues(params *CPZKPParams) (y1, y2 *big.Int)</a></dd>
				
			
				
				<dd><a href="#Verifier">type Verifier</a></dd>
				
				
					
					<dd>&nbsp; &nbsp; <a href="#Verifier.CreateProofChallenge">func (v *Verifier) CreateProofChallenge(params *CPZKPParams) (c *big.Int, err error)</a></dd>
				
					
					<dd>&nbsp; &nbsp; <a href="#Verifier.VerifyProof">func (v *Verifier) VerifyProof(y1, y2, r1, r2, c, s *big.Int, params *CPZKPParams) bool</a></dd>
				
			
			
			</dl>
			</div><!-- #manual-nav -->

		

		
			<h3>Package files</h3>
			<p>
			<span style="font-size:90%">
			
				<a href="/src/github.com/linchao/zkp_auth/internal/cpzkp/cp_zkp.go">cp_zkp.go</a>
			
			</span>
			</p>
		
		</div><!-- .expanded -->
		</div><!-- #pkg-index -->

		

		
		
		
		
			
			
			<h2 id="CPZKP">type <a href="/src/github.com/linchao/zkp_auth/internal/cpzkp/cp_zkp.go?s=151:172#L2">CPZKP</a>
				<a class="permalink" href="#CPZKP">&#xb6;</a>
				
				
			</h2>
			
			<pre>type CPZKP struct {
}
</pre>

			

			

			
			
			

			
				
				<h3 id="NewCPZKP">func <a href="/src/github.com/linchao/zkp_auth/internal/cpzkp/cp_zkp.go?s=552:583#L20">NewCPZKP</a>
					<a class="permalink" href="#NewCPZKP">&#xb6;</a>
					
					
				</h3>
				<pre>func NewCPZKP() (*<a href="#CPZKP">CPZKP</a>, <a href="/pkg/builtin/#error">error</a>)</pre>
				
				
				
			

			
				
				<h3 id="CPZKP.InitCPZKPParams">func (*CPZKP) <a href="/src/github.com/linchao/zkp_auth/internal/cpzkp/cp_zkp.go?s=689:746#L25">InitCPZKPParams</a>
					<a class="permalink" href="#CPZKP.InitCPZKPParams">&#xb6;</a>
					
					
				</h3>
				<pre>func (zkp *<a href="#CPZKP">CPZKP</a>) InitCPZKPParams() (*<a href="#CPZKPParams">CPZKPParams</a>, <a href="/pkg/builtin/#error">error</a>)</pre>
				<p>InitCPZKPParams initializes the Chaum-Pedersen ZKP protocol system params.

				
				
				
			
		
			
			
			<h2 id="CPZKPParams">type <a href="/src/github.com/linchao/zkp_auth/internal/cpzkp/cp_zkp.go?s=311:359#L7">CPZKPParams</a>
				<a class="permalink" href="#CPZKPParams">&#xb6;</a>
				
				
			</h2>
			<p>CPZKPParams represents the public parameters for the ZKP protocol.
p -&gt; primeP, q -&gt; primeQ, g -&gt; generatorG, and h -&gt; generatorH.

			<pre>type CPZKPParams struct {
<span id="CPZKPParams.p"></span>    p, q, g, h *<a href="/pkg/math/big/">big</a>.<a href="/pkg/math/big/#Int">Int</a>
}
</pre>

			

			

			
			
			

			

			
		
			
			
			<h2 id="Prover">type <a href="/src/github.com/linchao/zkp_auth/internal/cpzkp/cp_zkp.go?s=414:467#L12">Prover</a>
				<a class="permalink" href="#Prover">&#xb6;</a>
				
				
			</h2>
			<p>Prover represents the prover in the ZKP protocol.

			<pre>type Prover struct {
<span id="Prover.x"></span>    x *<a href="/pkg/math/big/">big</a>.<a href="/pkg/math/big/#Int">Int</a> <span class="comment">// Secret number x</span>
}
</pre>

			

			

			
			
			

			
				
				<h3 id="NewProver">func <a href="/src/github.com/linchao/zkp_auth/internal/cpzkp/cp_zkp.go?s=1639:1673#L64">NewProver</a>
					<a class="permalink" href="#NewProver">&#xb6;</a>
					
					
				</h3>
				<pre>func NewProver(x *<a href="/pkg/math/big/">big</a>.<a href="/pkg/math/big/#Int">Int</a>) *<a href="#Prover">Prover</a></pre>
				<p>NewProver creates a new Prover with the given secret password x.

				
				
			

			
				
				<h3 id="Prover.CreateProofChallengeResponse">func (*Prover) <a href="/src/github.com/linchao/zkp_auth/internal/cpzkp/cp_zkp.go?s=4074:4168#L128">CreateProofChallengeResponse</a>
					<a class="permalink" href="#Prover.CreateProofChallengeResponse">&#xb6;</a>
					
					
				</h3>
				<pre>func (p *<a href="#Prover">Prover</a>) CreateProofChallengeResponse(k, c *<a href="/pkg/math/big/">big</a>.<a href="/pkg/math/big/#Int">Int</a>, params *<a href="#CPZKPParams">CPZKPParams</a>) (s *<a href="/pkg/math/big/">big</a>.<a href="/pkg/math/big/#Int">Int</a>)</pre>
				<p>CreateProofChallengeResponse: prover creates the response to the verifier&apos;s challenge
Compute s = (k - c * x) mod q

				
				
				
			
				
				<h3 id="Prover.CreateProofCommitment">func (*Prover) <a href="/src/github.com/linchao/zkp_auth/internal/cpzkp/cp_zkp.go?s=2345:2436#L82">CreateProofCommitment</a>
					<a class="permalink" href="#Prover.CreateProofCommitment">&#xb6;</a>
					
					
				</h3>
				<pre>func (p *<a href="#Prover">Prover</a>) CreateProofCommitment(params *<a href="#CPZKPParams">CPZKPParams</a>) (k, r1, r2 *<a href="/pkg/math/big/">big</a>.<a href="/pkg/math/big/#Int">Int</a>, err <a href="/pkg/builtin/#error">error</a>)</pre>
				<p>CreateProofCommitment: creates a zero-knowledge proof commitment step based on the prover&apos;s y1 and y2 values.
The prover selects a random value k and commits (r1, r2) = (g^k mod p, h^k mod p).

				
				
				
			
				
				<h3 id="Prover.GenerateYValues">func (*Prover) <a href="/src/github.com/linchao/zkp_auth/internal/cpzkp/cp_zkp.go?s=1890:1961#L73">GenerateYValues</a>
					<a class="permalink" href="#Prover.GenerateYValues">&#xb6;</a>
					
					
				</h3>
				<pre>func (p *<a href="#Prover">Prover</a>) GenerateYValues(params *<a href="#CPZKPParams">CPZKPParams</a>) (y1, y2 *<a href="/pkg/math/big/">big</a>.<a href="/pkg/math/big/#Int">Int</a>)</pre>
				<p>GenerateYValues generates y1 and y2 for the prover based on the public parameters.
The prover calculates y1 = g^x mod p and y2 = h^x mod p.
y1 and y2 are public informations

				
				
				
			
		
			
			
			<h2 id="Verifier">type <a href="/src/github.com/linchao/zkp_auth/internal/cpzkp/cp_zkp.go?s=526:550#L17">Verifier</a>
				<a class="permalink" href="#Verifier">&#xb6;</a>
				
				
			</h2>
			<p>Verifier represents the verifier in the ZKP protocol.

			<pre>type Verifier struct {
}
</pre>

			

			

			
			
			

			

			
				
				<h3 id="Verifier.CreateProofChallenge">func (*Verifier) <a href="/src/github.com/linchao/zkp_auth/internal/cpzkp/cp_zkp.go?s=3345:3429#L107">CreateProofChallenge</a>
					<a class="permalink" href="#Verifier.CreateProofChallenge">&#xb6;</a>
					
					
				</h3>
				<pre>func (v *<a href="#Verifier">Verifier</a>) CreateProofChallenge(params *<a href="#CPZKPParams">CPZKPParams</a>) (c *<a href="/pkg/math/big/">big</a>.<a href="/pkg/math/big/#Int">Int</a>, err <a href="/pkg/builtin/#error">error</a>)</pre>
				<p>CreateProofChallenge: verifier creates a challenge to the prover by generating a random big integer
`c` which will be subsequently used by the prover in the `CreateProofChallengeResponse` step

				
				
				
			
				
				<h3 id="Verifier.VerifyProof">func (*Verifier) <a href="/src/github.com/linchao/zkp_auth/internal/cpzkp/cp_zkp.go?s=4624:4711#L139">VerifyProof</a>
					<a class="permalink" href="#Verifier.VerifyProof">&#xb6;</a>
					
					
				</h3>
				<pre>func (v *<a href="#Verifier">Verifier</a>) VerifyProof(y1, y2, r1, r2, c, s *<a href="/pkg/math/big/">big</a>.<a href="/pkg/math/big/#Int">Int</a>, params *<a href="#CPZKPParams">CPZKPParams</a>) <a href="/pkg/builtin/#bool">bool</a></pre>
				<p>VerifyProof verifies the zero-knowledge proof using the verifier&apos;s y1, y2, and the public parameters.
The verifier checks if r1 = (g^s * y1^c) mod p and r2 = (h^s * y2^c) mod p.
If both checks pass, the proof is valid, and the function returns true; otherwise, it returns false.

				
				
				
			
		
	

	







<div id="footer">
Build version go1.20.4.<br>
Except as <a href="https://developers.google.com/site-policies#restrictions">noted</a>,
the content of this page is licensed under the
Creative Commons Attribution 3.0 License,
and code is licensed under a <a href="/LICENSE">BSD license</a>.<br>
<a href="https://golang.org/doc/tos.html">Terms of Service</a> |
<a href="https://www.google.com/intl/en/policies/privacy/">Privacy Policy</a>
</div>

</div><!-- .container -->
</div><!-- #page -->
</body>
</html>
